<%@ page session="false" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://myfaces.apache.org/trinidad" prefix="tr"%>
<%@taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh"%>
<tr:panelGroupLayout partialTriggers="addCommissionButton saveCommissionButton">
	<fieldset>
	<legend>
		Lista prowizji
	</legend>
			<tr:commandLink shortDesc="Zapisz" id="saveCommissionButton"
						rendered="#{not empty priceParameter}"
						action="#{priceParameterController.savePriceParameter}"
						inlineStyle="color:orange" partialSubmit="true" >
				<tr:image source="gfx/save_button.png" />
		</tr:commandLink>
		
		<tr:commandLink shortDesc="Dodaj" immediate="true"
						inlineStyle="color:orange"
						rendered="#{empty priceParameter and currentUserTO.currentSalesman.permissionMap.PRICE_ADD}"
						actionListener="#{priceParameterController.addEmptyPriceParameter}"
						partialSubmit="true" id="addCommissionButton" >
				<tr:image source="gfx/add_button.png" />
		</tr:commandLink>

	<table cellpadding="3" cellspacing="0" width="100%">
	<tr>
		<td>
		<tr:inputText rendered="#{not empty priceParameter}" id="commissionName" columns="120"
						value="#{priceParameter.name}" label="Nazwa prowizji:" maximumLength="120"
						required="true" showRequired="false"/>
		</td>
		<td>
        <tr:inputText maximumLength="10" id="price" value="#{priceParameter.price}"
        					rendered="#{not empty priceParameter}" label="Cena:"
                            onkeypress="return checkField(window.self.event, NUMBER_FIELD)"
                            shortDesc="Cena jednostkowa" required="true">
        	<f:convertNumber groupingUsed="false" maxFractionDigits="2" minFractionDigits="2" locale="pl"/>
        </tr:inputText>
        </td>
	</tr>
	</table>

	<table width="100%" cellpadding="3" cellspacing="0" border="0" style="border: 1px solid #ccc">
		<tr style="background-color: #eee;">
			<td>nazwa</td>
			<td align="right">cena [PLN]</td>
			<td width="40" align="right">akcja</td>
		</tr>
		<tr:iterator var="priceParameter" rows="0" value="#{priceParameterController.priceParameters}"
					binding="#{priceParameterController.priceParameterIterator}" >
			<tr onMouseOver="this.style.backgroundColor='#e0ffc2'" onMouseOut="this.style.backgroundColor='#FFF'">
				<td style="border-top: 1px solid #ccc">
					<tr:outputText value="#{priceParameter.name}" />
				</td>
				<td style="border-top: 1px solid #ccc" align="right">
					<h:outputText value="#{priceParameter.price}" >
						<f:convertNumber groupingUsed="false" maxFractionDigits="2" minFractionDigits="2" locale="pl"/>
					</h:outputText>
				</td>
				<td align="right" style="border-top: 1px solid #ccc">
				<tr:commandLink shortDesc="Zmień" immediate="true" inlineStyle="margin-right:5px"
						actionListener="#{priceParameterController.editPriceParameter}"
						rendered="#{currentUserTO.currentSalesman.permissionMap.PRICE_REMOVE}">
					<tr:image source="gfx/edit.png" />
				</tr:commandLink>

				<tr:commandLink shortDesc="Usuń" immediate="true"
						actionListener="#{priceParameterController.removePriceParameter}"
						rendered="#{currentUserTO.currentSalesman.permissionMap.PRICE_REMOVE}"
						onclick="return confirmMessageBox('Czy chcesz usunąć tę prowizję?');">
					<tr:image source="gfx/delete.png" />
				</tr:commandLink>
				</td>
			</tr>
		</tr:iterator>
	</table>
	</fieldset>
</tr:panelGroupLayout>